
var materialArray;
var baseUrl="/weixin/";
var  table;
//相关业务逻辑
$(function(){
	page.bindTag();
	page.getAllMaterial();
	page.getProductionDepartment();
	page.getMaterialProcedure();
	page.removeBtnBind();
	page.remove();
});

var page={//页面总变量 
		//绑定页面元素
		pageAllMaterial:[],
		pageSelectArray:[],
		materialTypeArray:[],
		saveOtherId:'',
		bindTag:function(){
			/**
			 * 点击查询按钮
			 */
			$("#queryBtn").bind("click",function(){
				page.getMaterialProcedure();
			});
			
			
			
			/**
			 * 设置工序加工对象的时候，改变物料类型
			 */
			$("#publicMaterialType").bind("change",function(){
				page.materialTypeChange("publicMaterialType","publicMaterialArts");
			});
			
			
			/**
			 * 设置工序加工对象的时候，改变物料名称
			 */
//		    $("#publicMaterialName").bind("click",function(){
//		    	page.materialNameChange("publicMaterialType","publicMaterialName","publicMaterialQuality");
//		    });
			
			
			/**
			 * 设置物料组合的组合id
			 */
			$("#updateGroupIdModalBtn").bind("click",function(){
				var idArray=new Array();
				$(".removeBtn").each(function(){
					idArray.push($(this).val());
				});
				
				if(idArray.length<2){
					layAlert("至少需要两种物料");
					return false;
				}
				ajaxUtil.ajaxRuquest(baseUrl+"partsProcedure/updateGroupId",{"idArray":JSON.stringify(idArray),'beforeId':page.saveOtherId},function(data){
					layer.msg(data,{icon:1});
					table.ajax.reload(null,false);
					$("#saveOtherModal").modal("hide");
				});
				
			});
			
			
			
			
			/**
			 * 添加组合
			 */
			$("#addCombinationModalBtn").bind("click",function(){
				var idArray=new Array();
				$("#addProcedureTBody tr").each(function(){
					idArray.push($(this).data("selectMaterial").id);
				});
				if(idArray.length<2){
					layAlert("至少选择两种物料");
					return false;
				}
				var deptId=$("#deptId option:selected").val();
				if(deptId==''){
					layAlert("请选择部门");
					return false;
				}
				var array=new Array();
				var i=1;
				$("#addCombinationModal .right-box").find(".ui-sortable-handle").each(function(){
					var pro=new Object();
					pro.id=$(this).attr("data-id");
					pro.sort=i;
					array.push(pro);
					i++;
				});
				if(array.length<=0){
					layAlert("请选择要添加的工序");
					return false;
				}	
				var sendDate=new Object();
				sendDate.idArray=JSON.stringify(idArray);
				sendDate.procedureArray=JSON.stringify(array);
				sendDate.deptId=deptId;
				ajaxUtil.ajaxRuquest(baseUrl+"partsProcedure/addManyMaterial",sendDate,function(data){
					layer.msg(data,{icon:1});
					table.ajax.reload(null,false);
					$("#addCombinationModal").modal("hide");
				});
			});
			
			
			
			/**
			 * 鼠标移动tips
			 */
			$("#materialProcedureTable tbody").on("mouseover",".tips",function(){
				var otherMaching=$(this).attr("otherMaching");
				if(otherMaching==""){
					otherMaching="无";
				}
				layer.tips('加工对象：'+otherMaching, $(this), {
					  tips: [1, '#0FA6D8'] //还可配置颜色
				});
			});
			
			
			
			/**
			 * 点击设置加工对象
			 */
			$("#materialProcedureTable tbody").on("click",".tips",function(){
				var otherMaching=$(this).attr("otherMaching");
				var procedureId=$(this).val();
				var procedureName=$(this).text();
				var combinationId=$(this).parent().next().children(".deleteCombination").val();
				if(otherMaching==""){
					otherMaching="无";
				}
				$("#setProcedureMachingModalCombinationId").val(combinationId);
				$("#setProcedureMachingModalProcedureId").val(procedureId);
				$("#procedureName").text(procedureName);
				$("#maching").text(otherMaching);
				$("#setProcedureMachingModal").modal("show");
			});
			
			
		   /**
		    * 设置加工对象
		    */
		   $("#setProcedureMachingModalBtn").bind("click",function(){
			   var object=new Object();
			   object.maching=$("#publicMaterialType").val();
			   if($.inArray(object.maching, page.materialTypeArray)==-1 && object.maching!=''){
					layAlert("物料类型不存在");
					return false;
				}
//			   object.materialName=$("#publicMaterialName option:selected").val();
//			   object.materialQuality=$("#publicMaterialQuality option:selected").val();
			   object.arts=$("#publicMaterialArts option:selected").val();
			   object.combinationId=$("#setProcedureMachingModalCombinationId").val();
			   object.procedureId=$("#setProcedureMachingModalProcedureId").val();
			   ajaxUtil.ajaxRuquest(baseUrl+"partsProcedure/setProcedureMaching",object,function(data){
				   layer.msg(data,{icon:1});
				   $("#setProcedureMachingModal").modal("hide");
				   table.ajax.reload(null,false);
				});
		   });
			
		   /**
			 * 删除组合
			 */
			$("#materialProcedureTable tbody").on("click",".deleteCombination",function(){
				var input=$(this);
				layer.confirm('确定删除此组合？', {
					  btn: ['删除','取消'] //按钮
					}, function(){
						var id=input.val();
						ajaxUtil.ajaxRuquest(baseUrl+"partsProcedure/deleteManyMaterialGroup",{"id":id},function(data){
							layer.msg(data,{icon:1});
							table.ajax.reload(null,false);
						});
					});
				
				
			});
			
			/**
			 * 选择部门时重新设置工序
			 */
			$("#deptId").bind("change",function(){
				var deptId=$(this).val();
				page.getDeptProcedure(deptId);
				$("#addCombinationModal .right-box").html("");
			});
			
			/**
			 * 添加模态框模糊查询工序
			 */
			$("#addSearchWhereBtn").bind("click",function(){
				var deptId=$("#deptId option:selected").val();
				if(deptId==""){
					layAlert("请选择部门");
					return false;
				}
				page.getDeptProcedure(deptId);
			});
			
			
			/**
			 * 添加组合
			 */
			$("#addGroupBtn").bind("click",function(){
				if(page.pageAllMaterial == null || page.pageAllMaterial.length<=0){
					ajaxUtil.ajaxRuquest(baseUrl+"partsProcedure/getOneMaterial",null,function(data){
						page.pageAllMaterial=data;
						page.pageSelectArray=[];
						page.tableView(data,"selectMaterialModalTBody","selectMaterialModal");
						page.selectView(data,"materialTypeSelect","materialArtsSelect");
					});
				}else{
					page.pageSelectArray=[];
					page.tableView(page.pageAllMaterial,"selectMaterialModalTBody","selectMaterialModal");
					page.selectView(page.pageAllMaterial,"materialTypeSelect","materialArtsSelect");
				}
		    });
			
			
			/**
			 * 选择物料类型
			 */
			$("#materialTypeSelect").bind("change",function(){
				page.getArray();
			});
			
			
			/**
			 * 设置查询工序
			 */
		   $("#setSearchWhereBtn").bind("click",function(){
			   page.getCombinationNoHaveProcrdere();
		   });
			
			/**
			 * 保存修改
			 */
			$("#setCombinationModalBtn").bind("click",function(){
				page.setCombinationProcedure();
			});
			
			/**
			 * 选择物料名称
			 */
			$("#materialNameSelect").bind("change",function(){
				page.getArray();
			});
			
			
			/**
			 * 选择工艺
			 */
			$("#materialArtsSelect").bind("change",function(){
				page.getArray();
			});
			
			/**
			 * 选择物料材质
			 */
			$("#materialQualitySelect").bind("change",function(){
				page.getArray();
			});
			
			/**
			 *  选完确认
			 */
			$("#selectMaterialModalBtn").bind("click",function(){
				if(page.pageSelectArray.length<=0){
					layAlert("请选择要添加的物料");
					return false;
				}
				$("#addProcedureTBody").html("");
				for(var i=0;i<page.pageSelectArray.length;i++){
					var html=$(
						     "<tr>" +
						        "<td>"+page.pageSelectArray[i].materialType+"</td>" +
//						        "<td>"+page.pageSelectArray[i].materialName+"</td>" +
//						        "<td>"+page.pageSelectArray[i].materialQuality+"</td>" +
						        "<td>"+page.pageSelectArray[i].arts+"</td>" +
						        "<td><button class='btn btn-link remnoveMaterial'>移除</button></td>" +
						     "</tr>"		
						);
				   html.data("selectMaterial",page.pageSelectArray[i]);
				   $("#addProcedureTBody").append(html);
				}
				$("#selectMaterialModal").modal("hide");
				$("#addCombinationModal").modal("show");
				page.htmlBind();
			});
			
			
			/**
			 * 设置组合工序
			 */
			$("#materialProcedureTable tbody").on("click",".setCombination",function(){
				var id=$(this).val();
				page.getMaterialHaveAndNoHaveProcedure(id);
			});
			

		   /**
		    * 导出为excle
		    */
		   $("#downlodeExcle").bind("click",function(){
				var url=baseUrl+"partsProcedure/downlodeManyCombinationKeyPrucedureData";
				tableUtil.download(url);
		   });
		   
		   /**
		    * 点击工序另存为按钮
		    */
		   $("#materialProcedureTable tbody").on("click",".manySaveOther",function(){
				var id=$(this).val();
				page.saveOtherId=id;
				$("#haveMaterialTBody").html("");
				$("#noHaveMaterialWhere").html("");
				$("#saveOtherModal").modal("show");
				if(page.pageAllMaterial == null || page.pageAllMaterial.length<=0){
					ajaxUtil.ajaxRuquest(baseUrl+"partsProcedure/getOneMaterial",null,function(data){
						if(data.length<=0){
							layAlert("还未设置配件工艺");
							return false;
						}
						page.pageAllMaterial=data;
						page.saveOtherModalShow(page.pageAllMaterial);
					});
				}else{
					page.saveOtherModalShow(page.pageAllMaterial);
				}
		   });
		   
		   
		   /**
		    * 筛选没有设置过的物料
		    */
		   $("#noHaveSearchWhereBtn").bind("click",function(){
			   var haveArray=new Array();
			   $("#haveMaterialTBody tr").each(function(){
				   haveArray.push($(this).data("material"));
			   });
			   var idArray=_.map(haveArray, "id");
			   idArray=_.uniq(idArray);
			   var srarch=$("#noHaveMaterialWhere").val();
			   var  searchArray=_.filter(page.pageAllMaterial,function(xx){
					return (srarch=='' || xx.materialType.indexOf(srarch) !=-1 ||
					       xx.arts.indexOf(srarch) !=-1) && $.inArray(xx.id, idArray)==-1;
			  });
			   searchArray=_.uniq(searchArray);
			   $("#noHaveMaterialTBody").html("");
			   page.saveOtherModalShow(searchArray);
		   });
		},
		saveOtherModalShow:function(data){
			for(var key in data){
				var html=$("<tr>" +
						"<td>"+data[key].materialType+"</td>" +
//						"<td>"+data[key].materialName+"</span></td>" +
//						"<td>"+data[key].materialQuality+"</td>" +
						"<td>"+data[key].arts+"</td>" +
						"<td><button class='btn btn-link addBtn' value='"+data[key].id+"'>添加</button></td>" +
					  "</tr>");
				html.data('material',data[key]);
				$("#noHaveMaterialTBody").append(html);
			}
			page.htmlBind();
		},
//		materialNameChange:function(materialType,materialName,materialQuality){
//			 var materialType=$("#"+materialType).val();
//			 var materialName=$("#"+materialName).val();
//			 
//			 var materialTypeArray=_.filter(materialArray,{materialType:materialType,materialName:materialName});
//			 var materialQualityArray=_.map(materialTypeArray,"materialQuality");
//			 materialQualityArray=_.filter(materialQualityArray,function(xx){
//					return xx!='';
//			 });
//			 materialQualityArray=_.uniq(materialQualityArray);
//			 var html="<option value=''>请选择</option>";
//			 for(var i=0;i<materialQualityArray.length;i++){
//					 html+="<option value='"+materialQualityArray[i]+"'>"+materialQualityArray[i]+"</option>";
//			 }
//			 $("#"+materialQuality).html(html);
//		},
		materialTypeChange:function(materialType,arts){
			var materialType=$("#"+materialType).val();
//			var html="<option value=''>请选择</option>";
			var artsHtml="<option value=''>请选择</option>";
			
			//获取物料类型对应的物料信息
			var materialTypeArray=_.filter(materialArray,{materialType:materialType});
			//获取对应的物料类型
//			var materialNameArray=_.map(materialTypeArray, "materialName");
//			materialNameArray=_.filter(materialNameArray,function(xx){
//				return xx!='';
//			});
//			materialNameArray=_.uniq(materialNameArray);
//			for(var i=0;i<materialNameArray.length;i++){
//				html+="<option value='"+materialNameArray[i]+"'>"+materialNameArray[i]+"</option>";
//			}
			
			var artsArray=_.map(materialTypeArray, "arts");
			artsArray=_.filter(artsArray,function(xx){
				return xx!='';
			});
			artsArray=_.uniq(artsArray);
			for(var i=0;i<artsArray.length;i++){
				artsHtml+="<option value='"+artsArray[i]+"'>"+artsArray[i]+"</option>";
			}
			
//			$("#"+materialName).html(html);
			$("#"+arts).html(artsHtml);
//			$("#"+materialQuality).html("<option value=''>请选择</option>");
		},
		getArray:function(){
			var materialType=$("#materialTypeSelect option:selected").val();
//			var materialName=$("#materialNameSelect option:selected").val();
//			var materialQuality=$("#materialQualitySelect option:selected").val();
			var arts=$("#materialArtsSelect option:selected").val();
			var array=new Array();
			for(var i=0;i<page.pageAllMaterial.length;i++){
				var materialTypeBool=false;
//				var materialNameBool=false;
//				var materialQualityBool=false;
				var artsBool=false;
				if(materialType=='all' || materialType==page.pageAllMaterial[i].materialType){
					materialTypeBool=true;
				}
//				if(materialName=='all' || materialName==page.pageAllMaterial[i].materialName){
//					materialNameBool=true;
//				}
//				if(materialQuality=='all' || materialQuality==page.pageAllMaterial[i].materialQuality){
//					materialQualityBool=true;
//				}
				if(arts=='all' || arts==page.pageAllMaterial[i].arts){
					artsBool=true;
				}
				if(  materialTypeBool && artsBool){
					array.push(page.pageAllMaterial[i]);
				}
			}
			page.tableView(array,"selectMaterialModalTBody","selectMaterialModal");
			page.selectView(array,"materialTypeSelect","materialArtsSelect");
		},
		getAllMaterial:function(){
			ajaxUtil.ajaxRuquest(baseUrl+"partsProcedure/getCompanyMaterial",null,function(data){
				materialArray=data;
				var materialTypeArray=_.map(data, "materialType");
				materialTypeArray=_.uniq(materialTypeArray);
				page.materialTypeArray=materialTypeArray;
				var html="<option value=''>请选择</option>";
				for(var i=0;i<materialTypeArray.length;i++){
					html+="<option value='"+materialTypeArray[i]+"'>"+materialTypeArray[i]+"</option>";
				}
				$("#publicMaterialList").html(html);
				$("#materialTypeList").html(html);
			});
		},
		selectView:function(data,materialTypeSelect,materialArtsSelect){
			var materialType=$("#"+materialTypeSelect+" option:selected").val();
//			var materialName=$("#"+materialNameSelect+" option:selected").val();
//			var materialQuality=$("#"+materialQualitySelect+" option:selected").val();
			var materialArts=$("#"+materialArtsSelect+" option:selected").val();
			var materialTypeArray=new Array();
//			var materialNameArray=new Array();
//			var materialQualityArray=new Array();
			var materialArtsArray=new Array();
			$("#"+materialTypeSelect).html("<option value='all'>物料类型</option>");
//			$("#"+materialNameSelect).html("<option value='all'>物料名称</option>");
//			$("#"+materialQualitySelect).html("<option value='all'>物料规格</option>");
			$("#"+materialArtsSelect).html("<option value='all'>工艺</option>");
			for(var i=0;i<data.length;i++){
				//如果不包含
				if($.inArray(data[i].materialType, materialTypeArray)<=-1 && data[i].materialType != ''){
					materialTypeArray.push(data[i].materialType);
					$("#"+materialTypeSelect).append("<option value='"+data[i].materialType+"'>"+data[i].materialType+"</option>");
				}
//				if($.inArray(data[i].materialName, materialNameArray)<=-1 && data[i].materialName != ''){
//					$("#"+materialNameSelect).append("<option value='"+data[i].materialName+"'>"+data[i].materialName+"</option>");
//					materialNameArray.push(data[i].materialName);
//				}
//				if($.inArray(data[i].materialQuality, materialQualityArray)<=-1 && data[i].materialQuality != ''){
//					$("#"+materialQualitySelect).append("<option value='"+data[i].materialQuality+"'>"+data[i].materialQuality+"</option>");
//					materialQualityArray.push(data[i].materialQuality);
//				}
				if($.inArray(data[i].arts, materialArtsArray)<=-1 && data[i].arts != ''){
					$("#"+materialArtsSelect).append("<option value='"+data[i].arts+"'>"+data[i].arts+"</option>");
					materialArtsArray.push(data[i].arts);
				}
			}
			$("#"+materialTypeSelect+" option[value='"+materialType+"']").attr("selected",true);
//			$("#"+materialNameSelect+" option[value='"+materialName+"']").attr("selected",true);
//			$("#"+materialQualitySelect+" option[value='"+materialQuality+"']").attr("selected",true);
			$("#"+materialArtsSelect+" option[value='"+materialArts+"']").attr("selected",true);
		},
		tableView:function(data,selectMaterialModalTBody,selectMaterialModal){
		   $("#"+selectMaterialModalTBody).html("");
		   if(data.length<=0){
			   layAlert("没有查找到此物料");
			   return false;
		   }
		   for(var i=0;i<data.length;i++){
			   var xx="";
			   for(var j=0;j<page.pageSelectArray.length;j++){
				   if(page.pageSelectArray[j].id==data[i].id){
					   xx='checked';
					   break;
				   }
			   }
				var html=$(
				     "<tr>" +
				        "<td>"+data[i].materialType+"</td>" +
//				        "<td>"+data[i].materialName+"</td>" +
//				        "<td>"+data[i].materialQuality+"</td>" +
				        "<td>"+data[i].arts+"</td>" +
				        "<td><input type='checkbox' name='checkMaterial' "+xx+" /></td>" +
				     "</tr>"		
				);
				html.data("material",data[i]);
				$("#"+selectMaterialModalTBody).append(html);
			}
			$("#"+selectMaterialModal).modal("show");
			page.htmlBind();
		},
		htmlBind:function(){
			$("#selectMaterialModalTBody input[type='checkbox']").unbind("click");
			$(".remnoveMaterial").unbind("click");
			$(".addBtn").unbind("click");
			$(".removeBtn").unbind("click");
			/**
			 *  选择物料
			 */
			$("#selectMaterialModalTBody input[type='checkbox']").bind("click",function(){
				var bool=$(this).is(':checked');
				var material=$(this).parents("tr").data("material");
				if(bool){
					page.pageSelectArray.push(material);
				}else{
					for(var i=0;i<page.pageSelectArray.length;i++){
						if(page.pageSelectArray[i].id==material.id){
							page.pageSelectArray.splice(i,1);
							break;
						}
					}
				}
				layer.msg("选择条数"+page.pageSelectArray.length,{icon:1});
			});
			
			
			/**
			 * 移除物料
			 */
			$(".remnoveMaterial").bind("click",function(){
				var tr=$(this).parents("tr");
				tr.remove();
			});
			
			/**
			 * 添加物料
			 */
			$(".addBtn").bind("click",function(){
				$(this).removeClass("addBtn");
				$(this).addClass("removeBtn");
				$(this).text("移除");
				$("#haveMaterialTBody").append($(this).parents("tr"));
				page.htmlBind();
			});
			
			/**
			 *  移除物料
			 */
			$(".removeBtn").bind("click",function(){
				$(this).addClass("addBtn");
				$(this).removeClass("removeBtn");
				$(this).text("添加");
				$("#noHaveMaterialTBody").append($(this).parents("tr"));
				page.htmlBind();
			});
		},
		getProductionDepartment:function(){
			ajaxUtil.ajaxRuquest(baseUrl+"basicData/getProductionDepartment",null,function(data){
				var html="<option value=''>请选择</option>";
				for(var i=0;i<data.length;i++){
						html+="<option value='"+data[i].id+"'>"+data[i].deptName+"</option>";
				}
				$("#deptId").html(html);
			});
		},
		getMaterialProcedure:function(){
			var materialType=$("#searchMaterialType").val();
			var arts=$("#searchArts").val();
			
			
			table=ajaxUtil.dataTablesAjax("materialProcedureTable",5,baseUrl+"partsProcedure/getManyMaterialProcedure",
					{"materialType":materialType,"arts":arts},[
						{"data":"materialList",render: function (data,type,row){
							var html="";
							for(var i=0;i<data.length;i++){
								var x=i+1;
								html+=x+"、"+data[i].materialType;
//								if(data[i].materialName!=''){
//									html+="-"+data[i].materialName;
//								}
//								if(data[i].material!=''){
//									html+="-"+data[i].material;
//								}
								if(data[i].arts!=''){
									html+="+"+data[i].arts;
								}
								html+="<br/>";
							}
							return html;
						}},
						{"data":"procedureList",render: function (data,type,row){
							var html="";
							for(var i=0;i<data.length;i++){
								var otherMaching=data[i].otherMaching;
//								if(data[i].materialName!=''){
//									otherMaching+="-"+data[i].materialName;
//								}
//								if(data[i].materialQuality!=''){
//									otherMaching+="-"+data[i].materialQuality;
//								}
								if(data[i].arts!=''){
									otherMaching+="+"+data[i].arts;
								}
								html+=" <button class='btn tips' value='"+data[i].procedureId+"' otherMaching='"+otherMaching+"'>"+data[i].workShopName+'-'+data[i].procedureName+"</button>";
							}
							return html;
						}},
						{"data":"id",render: function (data,type,row){
							return "<button class='btn btn-link deleteCombination' value='"+data+"'>删除</button>" +
								   "<button class='btn btn-link setCombination' value='"+data+"' >设置工序</button>"+
							       "<button class='btn btn-link manySaveOther' value='"+data+"' >工序另存为</button>";
						}}
			        ]
				);
		},
		getDeptProcedure:function(deptId){
			var searchWhere=$("#addSearchWhereInput").val();
			ajaxUtil.ajaxRuquest(baseUrl+"partsProcedure/getDeptProcedure",{"deptId":deptId,"searchWhere":searchWhere},function(data){
				var html="";
				for(var i=0;i<data.length;i++){
					html+="<li class='item ui-sortable-handle'  data-id="+data[i].id+">"+data[i].workshopName+'-'+data[i].processName+"</li>";
				}
				$("#addCombinationModal .left-box").html(html);
//				$("#addCombinationModal .right-box").html("");
				page.leftAndRightBind();
			});
		},
		setCombinationProcedure:function(){
			var id=$("#setModalCombinationId").val();
			var array=new Array();
			var i=1;
			$("#setCombinationModal .right-box").find(".ui-sortable-handle").each(function(){
				var pro=new Object();
				pro.id=$(this).attr("data-id");
				pro.maching=$(this).attr("maching");
//				pro.materialName=$(this).attr("materialName");
//				pro.materialQuality=$(this).attr("materialQuality");
				pro.arts=$(this).attr("arts");
				pro.sort=i;
				array.push(pro);
				i++;
			});
			if(array.length<=0){
				layAlert("如要移除所有工序，请删除此组合");
				return false;
			}	
			ajaxUtil.ajaxRuquest(baseUrl+"partsProcedure/setManymaterialProcrdure",{"id":id,"procedureArray":JSON.stringify(array)},function(data){
				layer.msg(data,{icon:1});
				$("#setCombinationModal").modal("hide");
				table.ajax.reload(null,false);
			});
		},
		getMaterialHaveAndNoHaveProcedure:function(id){
			ajaxUtil.ajaxRuquest(baseUrl+"partsProcedure/getManyMaterialHaveAndNoHaveProcedure",{"id":id},function(data){
				var combinationKey=data.combinationKey;
				var processListHave=data.processListHave;
				var processListNoHave=data.processListNoHave;
//				var titleHtml="";
				var leftHtml="";
				var rightHtml="";
//				标题内容
//				titleHtml=combinationKey.materialType+"-"+combinationKey.materialName+"-"+combinationKey.materialQuality;
//				左边没有的工序
				for(var i=0;i<processListNoHave.length;i++){
					leftHtml+="<li class='item ui-sortable-handle'  data-id="+processListNoHave[i].id+">"+processListNoHave[i].workshopName+'-'+processListNoHave[i].processName+"</li>";
				}
//				右边有的工序
				for(var i=0;i<processListHave.length;i++){
					var maching=processListHave[i].maching;
					if(maching!=''){
						maching="_"+maching;
						if(processListHave[i].materialName!=''){
							maching+="_"+processListHave[i].materialName;
						}
					}
					rightHtml+="<li class='item ui-sortable-handle'  data-id="+processListHave[i].id+" maching='"+processListHave[i].maching+"'  arts='"+processListHave[i].arts+"'>"+processListHave[i].workshopName+"-"+processListHave[i].processName+"<span style='color:red'>"+maching+"</span>"+"</li>";
				}
//				$("#setModalCombinationTitle").text(titleHtml);
				$("#setModalDeptName").text(combinationKey.deptName);
				$("#setModalCombinationId").val(combinationKey.id);
				$("#setModalCombinationDeptId").val(combinationKey.deptId);
				$("#setCombinationModal .left-box").html(leftHtml);
				$("#setCombinationModal .right-box").html(rightHtml);
				$("#setCombinationModal").modal("show");
				page.leftAndRightBindSet();
			});
		},
		getCombinationNoHaveProcrdere:function(){
			var id=$("#setModalCombinationId").val();
			var deptId=$("#setModalCombinationDeptId").val();
			var searchWhere=$("#setSearchWhereInput").val();
			ajaxUtil.ajaxRuquest(baseUrl+"partsProcedure/getCombinationNoHaveProcrdere",{"id":id,"deptId":deptId,"searchWhere":searchWhere},function(data){
				var processListNoHave=data;
			    var leftHtml="";
			    for(var i=0;i<processListNoHave.length;i++){
					leftHtml+="<li class='item ui-sortable-handle'  data-id="+processListNoHave[i].id+">"+processListNoHave[i].workshopName+'-'+processListNoHave[i].processName+"</li>";
				}
			    $("#setCombinationModal .left-box").html(leftHtml);
			    page.leftAndRightBindSet();
			});
		},
		leftAndRightBind:function(){
			$(".item").unbind("click");
			$(".left-box .item").unbind("dblclick");
			$(".right-box .item").unbind("dblclick");
			//单击
			$(".item").bind("click",function(){
				$(this).toggleClass("selected-item");
			});
			
			//左边双击右移
			$(".left-box .item").bind("dblclick",function(){
				$(".right-box").append($(this).removeClass('selected-item'));
				page.leftAndRightBind();
			});
			
            //右边双击左移
			$(".right-box .item").bind("dblclick",function(){
				$(".left-box").append($(this).removeClass('selected-item'));
				page.leftAndRightBind();
			});
		},
		leftAndRightBindSet:function(){
			$("#setCombinationModal .item").unbind("click");
			$("#setCombinationModal .left-box .item").unbind("dblclick");
			$("#setCombinationModal .right-box .item").unbind("dblclick");
			//单击
			$("#setCombinationModal .item").bind("click",function(){
				$(this).toggleClass("selected-item");
			});
			
			//左边双击右移
			$("#setCombinationModal .left-box .item").bind("dblclick",function(){
				$("#setCombinationModal .right-box").append($(this).removeClass('selected-item'));
				page.leftAndRightBind();
			});
			
			//右边双击左移
			$("#setCombinationModal .right-box .item").bind("dblclick",function(){
				$("#setCombinationModal .left-box").append($(this).removeClass('selected-item'));
				page.leftAndRightBind();
			});
		},
		removeBtnBind:function(){
			$("#addCombinationModal .add-one").bind("click",function(){
				$("#addCombinationModal .right-box").append($("#addCombinationModal .left-box").find('.selected-item').removeClass('selected-item'));
			});
			
			$("#addCombinationModal .add-all").bind("click",function(){
				$("#addCombinationModal .right-box").append($("#addCombinationModal .left-box").find('.item').removeClass('selected-item'));
			});
			
			$("#addCombinationModal .remove-one").bind("click",function(){
				$("#addCombinationModal .left-box").append($("#addCombinationModal .right-box").find('.selected-item').removeClass('selected-item'));
			});
			
			$("#addCombinationModal .remove-all").bind("click",function(){
				$("#addCombinationModal .left-box").append($("#addCombinationModal .right-box").find('.item').removeClass('selected-item'));
			});
			$("#setCombinationModal .add-one").bind("click",function(){
				$("#setCombinationModal .right-box").append($("#setCombinationModal .left-box").find('.selected-item').removeClass('selected-item'));
			});
			
			$("#setCombinationModal .add-all").bind("click",function(){
				$("#setCombinationModal .right-box").append($("#setCombinationModal .left-box").find('.item').removeClass('selected-item'));
			});
			
			$("#setCombinationModal .remove-one").bind("click",function(){
				$("#setCombinationModal .left-box").append($("#setCombinationModal .right-box").find('.selected-item').removeClass('selected-item'));
			});
			
			$("#setCombinationModal .remove-all").bind("click",function(){
				$("#setCombinationModal .left-box").append($("#setCombinationModal .right-box").find('.item').removeClass('selected-item'));
			});
		},
		//工序移动排序
		remove:function(){
			$('.item-box').sortable({
				placeholder: 'item-placeholder',
				connectWith: '.item-box',
				revert: true
			}).droppable({
				accept: '.item',
				hoverClass: 'item-box-hover',
				drop: function(event, ui){
					setTimeout(function(){
						ui.draggable.removeClass('selected-item');
					}, 500);
				}
			}).disableSelection();
		}
		
}